package justtry.sort;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by weishaofei on 2017/12/10.
 */
public class QuickSort {

    public static void sort(List<Integer> list) {
        if (list.size() <= 1) {
            return;
        }
        List<Integer> front = new ArrayList<Integer>();
        List<Integer> back = new ArrayList<Integer>();
        int partition = list.get(0);
        for (int index = 1; index < list.size(); index++) {
            if (list.get(index) < partition) {
                front.add(list.get(index));
            } else {
                back.add(list.get(index));
            }
        }
        list = new ArrayList<Integer>();
        list.addAll(front);
        list.addAll(back);
        sort(front);
        sort(back);
    }

    private void partition(List<Integer> list, int begin, int end) {
        int partitionValue = list.get(begin);
        int i = begin;
        int j = end;
        while (true) {
            while (list.get(++i) < partitionValue) {
                if (i == end) {
                    break;
                }
            }
            while (list.get(--j) < partitionValue) {
                if (j == begin) {
                    break;
                }
            }
            if (i >= j) {
                break;
            }
            exch(list, i, j);
        }

    }

    private void exch(List<Integer> list, int sr, int des) {
        int temp = list.get(sr);
        list.set(sr, list.get(des));
        list.set(des, temp);
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(49);
        list.add(39);
        list.add(169);
        list.add(1);
        list.add(10);
//        sort(list);
//        System.out.println(list);
        int j=1;
        System.out.println(j--);
        System.out.println(j);
        System.out.println(--j);
    }
}
